import { http } from '@/utils/request'
import type {
  User,
  UserLoginRequest,
  UserRegisterRequest,
  UserUpdateRequest,
  UserAdminUpdateRequest,
  UserQueryRequest,
  UpdateRequest,
  BaseResponse,
  PageResponse
} from '@/types'

// 用户登录
export const login = (data: UserLoginRequest): Promise<BaseResponse<User>> => {
  return http.post('/user/login', data)
}

// 用户注销
export const logout = (): Promise<BaseResponse<boolean>> => {
  return http.post('/user/logout')
}

// 用户注册（仅管理员可用）
export const register = (data: UserRegisterRequest): Promise<BaseResponse<number>> => {
  return http.post('/user/register', data)
}

// 获取当前登录用户信息
export const getCurrentUser = (): Promise<BaseResponse<User>> => {
  return http.post('/user/get/login')
}

// 更新用户信息
export const updateUser = (data: UserUpdateRequest): Promise<BaseResponse<boolean>> => {
  return http.post('/user/update', data)
}

// 分页获取用户列表
export const getUserList = (data: UserQueryRequest): Promise<BaseResponse<PageResponse<User>>> => {
  return http.post('/user/list/page', data)
}

// 删除用户
export const deleteUser = (data: UpdateRequest): Promise<BaseResponse<boolean>> => {
  return http.post('/user/delete', data)
}

// 管理员更新用户信息
export const adminUpdateUser = (data: UserAdminUpdateRequest): Promise<BaseResponse<boolean>> => {
  return http.post('/user/admin/update', data)
}
